package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.jdbc.StringUtils;
import com.project.entity.Customer;
import com.project.mapper.TCustomerMapper;
import com.project.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhangyang
 * @since 2021-10-06
 */
@Service
public class TCustomerServiceImpl extends ServiceImpl<TCustomerMapper, Customer> implements ICustomerService {

    @Autowired
    private TCustomerMapper customerMapper;

    @Override
    public List<Customer> findByItem(String realName, String phone) {
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        if (!StringUtils.isNullOrEmpty(realName)) {
            wrapper.like("c_realName", realName);
        }
        if (!StringUtils.isNullOrEmpty(phone)) {
            wrapper.like("c_phone", phone);
        }
        return customerMapper.selectList(wrapper);
    }

    @Override
    public Customer findById(String id) {
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.eq("c_code",id);
        return customerMapper.selectOne(wrapper);
    }

}
